package com.om.app;

import com.om.android.FbDialog;
import com.om.android.Hackbook;
import com.om.data.DataManager;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.text.Html;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.ImageView;

public class HomePageActivity extends Activity {

	boolean isFreeApp = false;

	/** Called when the activity is first created. */
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.home_screen);
	}

	public void act(View v) {
		ImageView ib = (ImageView) v;
		//check if it's the first btn
		String btnName = getResources().getResourceName(ib.getId());
		btnName = btnName.substring(btnName.length()-1, btnName.length());
		int num = Integer.valueOf(btnName);
		if (num == 1 || (num > 0 && !isFreeApp)) {
			Intent i = new Intent();
			i.setClass(this, QuestionActivity.class);		
			DataManager dm = DataManager.getInstance();
			dm.setQuestionType(btnName);
			startActivity(i);
		}
		else {
			AlertDialog.Builder builder = new AlertDialog.Builder(this);
			String msg = "Please install the real app";
			
				//textView.setText();
				builder.setMessage(Html.fromHtml("<a href=\"market://details?id=com.appspot.swisscodemonkeys.apps&hl=pt_PT\">CLICK HERE</a>")).setPositiveButton("Ok", new DialogInterface.OnClickListener() {

					@Override
					public void onClick(DialogInterface dialog, int which) {
						dialog.dismiss();
					}
				}).setOnCancelListener(new DialogInterface.OnCancelListener() {

					@Override
					public void onCancel(DialogInterface dialog) {
						finish();
					}
				});
				builder.create().show();
			}	
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
	    MenuInflater inflater = getMenuInflater();
	    inflater.inflate(R.menu.om_menu, menu);
	    
	    return true;
	}
	
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()){
        case R.id.about:
    		Intent i = new Intent();
    		i.setClass(this, AboutUsActivity.class);		
    		startActivity(i);
            return true;
        default:
            return super.onOptionsItemSelected(item);
        }	    	
    }

	
}